package game.systems.light.lightBeam
{
	import engine.classes.enumerations.SystemPriority;
	import engine.systems.update.GameSystem;
	
	import flash.display.CapsStyle;
	import flash.display.GradientType;
	import flash.display.LineScaleMode;
	import flash.display.SpreadMethod;
	import flash.display.Sprite;
	import flash.geom.Matrix;
	
	
	public class LightBeamSystem extends GameSystem
	{
		private var matrix:Matrix 	= new Matrix();
		private var alphas:Array 	= [0, 1];
		private var ratios:Array 	= [150, 255];
		
		public function LightBeamSystem()
		{
			super(LightBeamNode, updateNode);
			
			this.priority = SystemPriority.UPDATE;
		}
		
		private function updateNode(node:LightBeamNode, time:Number):void
		{
			if(node.beam.invalidate)
			{
				node.beam.invalidate = false;
				
				matrix.createGradientBox(node.beam.length, node.beam.thickness, Math.PI / 2, 0, -node.beam.thickness);
				
				var line:Sprite = node.render.display as Sprite;
				line.graphics.clear();
				line.graphics.lineStyle(node.beam.thickness, 0, 1, false, LineScaleMode.NORMAL, CapsStyle.NONE);
				line.graphics.lineGradientStyle(GradientType.LINEAR, [node.beam.color, node.beam.color], alphas, ratios, matrix, SpreadMethod.REFLECT);
				line.graphics.lineTo(node.beam.length, 0);
				line.graphics.endFill();
			}
		}
	}
}